package com.proj.hot.utils;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import android.util.Log;

/**
 * @description: 文件工具类
 * @author: Ares Zhao
 * @date: 2015-5-20 下午1:28:38
 */
public class FileUtil
{
	private static final String TAG = "FileUtil";
	
	/**
	 * @description: 将文件的字符数组保存成文件
	 * @param fileByteArray 文件的字符数组
	 * @param filePath 文件保存路径
	 * @param fileName 文件名
	 */
	public static void saveByteToFile(byte[] fileByteArray, String filePath, String fileName)
	{
		BufferedOutputStream bos = null;
		FileOutputStream fos = null;
		File file = null;
		try
		{
			Log.d(TAG, filePath + "/" + fileName);
			File dir = new File(filePath);
			if (!dir.exists() && dir.isDirectory())
			{// 判断文件目录是否存在
				dir.mkdirs();
			}
			file = new File(filePath + "/" + fileName);
			fos = new FileOutputStream(file);
			bos = new BufferedOutputStream(fos);
			bos.write(fileByteArray);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			if (bos != null)
			{
				try
				{
					bos.close();
				}
				catch (IOException e1)
				{
					e1.printStackTrace();
				}
			}
			if (fos != null)
			{
				try
				{
					fos.close();
				}
				catch (IOException e1)
				{
					e1.printStackTrace();
				}
			}
		}
	}
}
